package com.lmk.qs.jdbc;

import com.lmk.qs.domain.Emp2;
import com.lmk.qs.utils.DruidUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Text08 {
    public static void main(String[] args) throws SQLException {
        List<Emp2> emp=new Text08().findAll();
        System.out.println(emp);

    }
    public List<Emp2>  findAll() throws SQLException {
        ResultSet resultSet=null;
        Connection connection=null;
        Statement st=null;
        List<Emp2> list=new ArrayList<>();
        connection= DruidUtil.getConnection();
        String sql="select * from emp";
        st=connection.createStatement();
        Emp2 emp=null;
        resultSet=st.executeQuery(sql);
        while (resultSet.next()){
            int id= resultSet.getInt(1);
            String name= resultSet.getString(2);
            String gender=resultSet.getString(3);
            int salary= resultSet.getInt(4);
            int jobdate= resultSet.getInt(5);
            int  dep_id= resultSet.getInt(6);
            emp=new Emp2();
            emp.setId(id);
            emp.setName(name);
            emp.setGender(gender);
            emp.setSalary(salary);
            emp.setJobdate(jobdate);
            emp.setDepid(dep_id);
            list.add(emp);

        }
        return list;

    }
}
